package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.SysCollectResp;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCollect;
import com.ruoyi.system.service.ISysCollectService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 酒店收藏Controller
 * 
 * @author dht
 * @date 2025-04-28
 */
@RestController
@RequestMapping("/system/collect")
public class SysCollectController extends BaseController
{
    @Autowired
    private ISysCollectService sysCollectService;

    /**
     * 查询酒店收藏列表
     */
//    @PreAuthorize("@ss.hasPermi('system:collect:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(SysCollect sysCollect)
//    {
//        startPage();
//        List<SysCollect> list = sysCollectService.selectSysCollectList(sysCollect);
//        return getDataTable(list);
//    }
    @PreAuthorize("@ss.hasPermi('system:collect:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCollect sysCollect)
    {
        startPage();
        List<SysCollectResp> list = sysCollectService.selectSysCollectRespList(sysCollect);
        return getDataTable(list);
    }

    /**
     * 导出酒店收藏列表
     */
    @PreAuthorize("@ss.hasPermi('system:collect:export')")
    @Log(title = "酒店收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCollect sysCollect)
    {
        List<SysCollect> list = sysCollectService.selectSysCollectList(sysCollect);
        ExcelUtil<SysCollect> util = new ExcelUtil<SysCollect>(SysCollect.class);
        util.exportExcel(response, list, "酒店收藏数据");
    }

    /**
     * 获取酒店收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:collect:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(sysCollectService.selectSysCollectByUserId(userId));
    }

    /**
     * 新增酒店收藏
     */
    @PreAuthorize("@ss.hasPermi('system:collect:add')")
    @Log(title = "酒店收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCollect sysCollect)
    {
        return toAjax(sysCollectService.insertSysCollect(sysCollect));
    }

    /**
     * 修改酒店收藏
     */
    @PreAuthorize("@ss.hasPermi('system:collect:edit')")
    @Log(title = "酒店收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCollect sysCollect)
    {
        return toAjax(sysCollectService.updateSysCollect(sysCollect));
    }

    /**
     * 删除酒店收藏
     */
    @PreAuthorize("@ss.hasPermi('system:collect:remove')")
    @Log(title = "酒店收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sysCollectService.deleteSysCollectByUserIds(userIds));
    }

    @GetMapping("/front/list")
    public TableDataInfo frontList(SysCollect sysCollect)
    {
        startPage();
        List<SysCollectResp> list = sysCollectService.selectSysCollectRespFrontList(sysCollect);
        return getDataTable(list);
    }

    @PostMapping("/front/add")
    public AjaxResult frontAdd(@RequestBody SysCollect sysCollect)
    {
        return toAjax(sysCollectService.insertSysCollect(sysCollect));
    }

    @DeleteMapping("/front/delete/{hotelId}")
    public AjaxResult frontRemove(@PathVariable Long hotelId)
    {
        return toAjax(sysCollectService.deleteSysCollectByHotelId(hotelId));
    }
}
